﻿using Company.Application.Share.Entities;
using Company.Application.Share.Interfaces;
using Company.Application.Station.Services;
using Company.Core.Models;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Company.Application.Station.ViewModels
{
    internal class StationViewModel: BindableBase
    {
        public ICommand LoadedCommand { get; }
        public ICommand SelectStationCommand { get; }
        public ISession Session { get; }
        public IStationManager StationManager { get; }
        private IRegionManager RegionManager { get; }
        public StationViewModel(
            IRegionManager regionManager,
            IStationManager stationManager, 
            ISession session)
        {
            RegionManager = regionManager;
            StationManager = stationManager;
            LoadedCommand = new DelegateCommand(OnLoadedCommand);
            SelectStationCommand = new DelegateCommand<StationEntity>(OnSelectStationCommand);
            Session = session;
        }
        private void OnSelectStationCommand(StationEntity station)
        {
            StationManager.Station = station;
            NavigationParameters param = new()
            {
                {"StationEntity",station }
            };
            RegionManager.RequestNavigate(Names.MainRegion, Names.DeviceView, param);
        }
        private void OnLoadedCommand()
        {
            StationManager.StartAsync();
        }
    }
}
